package br.fatec.ppi.entities.student;

import br.fatec.ppi.entities.ISearchable;
import br.fatec.ppi.entities.Student;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class StudentFacade {
    
    private ISearchable<Student> search;
    
    public List<Student> SearchByName(String name){
         return new SearchByName(name).doSearch();
    }
    
    public List<Student> SearchByAge(int age){
        return new SearchByAge(age).doSearch();
    }
    
    public List<Student> SearchByFullName(String fullName){
        return new SearchByFullName(fullName).doSearch();
    }
    
    public List<Student> SerchByRangeOfAge(int age1, int age2){
        return new SearchByRangeOfAge(age1, age2).doSearch();
    }
    
    public void Save(Student student){
        EntityManager entityManager = Persistence.createEntityManagerFactory("schoolPersistenceModel").createEntityManager();
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        entityManager.persist(student);
        transaction.commit();
    }
}